<template>
  <div></div>
</template>

<script>
const $ = require("jquery");
import { getSSCApplyInfo, getSSCSign } from "@/apis/test";
import config from "../test/config";
import Dialog from "@/components/common/dialog/Dialog.vue";
import { thirdLogin } from "../../apis";
import * as types from "../../store/mutation-types";
export default {
  data() {
    return {
      username: "test915",
      password: "123456"
    };
  },
  created() {
    this.initData();
  },
  methods: {
    initData() {
      this.$store.commit(types.REMOVE_ALL);
      thirdLogin({
        username: this.username,
        password: this.password
      }).then(res => {
        localStorage.setItem("token", res.access_token);
        this.getInfo();
      });
    },
    getInfo() {
      getSSCApplyInfo().then(res => {
        console.log("sssss", res);
        if (
          res.data &&
          (res.data.signFlag === "0" || res.data.signFlag === "2")
        ) {
          // 0未签发，1本渠道已签发，2其他渠道已签发
          this.apply(res.data); // 签发
        } else if (res.data && res.data.signFlag === "1") {
          this.showCode(res.data); //展码
        }
      });
    },
    showCode(data) {
      let params = {
        channelNo: data.channelNo,
        signNo: data.signNo,
        returnUrl: "http://10.19.92.209:8880",
        isWeb: "1"
      };
      getSSCSign(params).then(res => {
        // location.href = `${config.sscServer}/indep/cardInfo?${res.data}`;
        location.href = `${config.sscServer}/indep/ORCode?${res.data}`;
        // console.log("code", `${config.sscServer}/indep/ORCode?${res.data}`);
      });
    },
    apply(data) {
      let params = {
        channelNo: data.channelNo,
        returnUrl: "http://10.19.92.209:8880",
        isWeb: "1"
      };
      getSSCSign(params).then(res => {
        // console.log("eeeee", `${config.sscServer}/main?${res.data}`);
        location.href = `${config.sscServer}/main?${res.data}`;
      });
    }
  }
};
</script>
